﻿using System;
using System.Windows.Data;
using AccessControl.Contracts.Models;
using AccessControl.Gateway.Managers;

namespace AccessControl.Wpf.Converters
{
	class SensorToRelatedEntryConverter : IValueConverter
	{
		#region IValueConverter Members

		public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			ISensor sensor = (ISensor)value;
			foreach (IEntry entry in Session.Instance.EntriesManager.Items)
			{
				if (entry.Id == sensor.RelatedEntryId)
				{
					if (parameter != null && parameter.Equals("Name"))
						return entry.Name;
					
					return entry;
				}
			}

			return null;
		}

		public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			throw new NotImplementedException();
		}

		#endregion
	}
}
